package com.momo.mal.anime.overall;

import net.momo.mal.R;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;

import com.viewpagerindicator.IconPagerAdapter;

public class AnimeOverallAdapter extends FragmentPagerAdapter implements IconPagerAdapter {
	protected static final String[] CONTENT = new String[] { "Watching", "Complete", "On-Hold", "Dropped", "Plan to Watch" };
	protected static final int[] ICONS = new int[] {
		R.drawable.ic_menu_add,
		R.drawable.ic_menu_add,
		R.drawable.ic_menu_add,
		R.drawable.ic_menu_add
	};
	private int sort;
	
	private int mCount = CONTENT.length;

	public AnimeOverallAdapter(FragmentManager fm, int sort) {
		super(fm);
 		this.sort = sort;
	}
	
	@Override
	public int getIconResId(int index) {
		return ICONS[index % ICONS.length];
	}

	@Override
	public Fragment getItem(int position) {
		Log.d("getitem", sort + " asdas");
		if(position == 0) {
			return AnimeTabWatching.newInstance(sort);
		} else if(position == 1) {
			return AnimeTabComplete.newInstance(sort);
		} else if(position == 2) {
			return AnimeTabOnHold.newInstance(sort);
		} else if(position == 3) {
			return AnimeTabDropped.newInstance(sort);
		} else {
			return AnimeTabPlanToWatch.newInstance(sort);
		}
	}
	
	@Override
	public int getCount() {
		return mCount;
	}

	@Override
    public CharSequence getPageTitle(int position) {
		return AnimeOverallAdapter.CONTENT[position % CONTENT.length];
    }
	
	public void setCount(int count) {
        if (count > 0 && count <= 10) {
            mCount = count;
            notifyDataSetChanged();
        }
    }
}
